package com.me.libgdx_test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;

public class ClassHudObject {
	private ArrayList<ClassHudFit> spells;
	private ArrayList<ClassRectangle> rectangles;
	private ArrayList<ClassHudFit> hud_objects;
	private ArrayList<ClassHudText> hud_text;
	private ClassHudFit hud, spell_selector;
	private ClassCharacterPlayer player;
	private ClassLogDisplay logger;
	private ClassPlaceObjects objects;
	private String path;
	private Point screen_size;
	//These are the click rectangles for the hud
	private Rectangle mana_potion,health_potion,enter_location,player_info,enemy_info;
	private Rectangle[] spell_areas;
	private ClassCursorAt cursor_object;
	private ClassHudFit spell_icon = new ClassHudFit();
	private SpellInfo spell_info;
	private static Vector3 button_color = new Vector3(.5f,.5f,0);
	private String image_gold, image_piety, image_spells, image_hud, image_hud_details;
	private boolean details, info;
	private ClassHudWrapper hud_wrapper;
	private CopyOnWriteArrayList<ClassAnimationIterator> animations;
	private CopyOnWriteArrayList<ClassAnimationString> animation_text;
	private ClassAnimationTextureLoader animation_loader;
	
	public ClassHudObject(String path, Point screen_size, CopyOnWriteArrayList<ClassAnimationIterator> animations, 
			CopyOnWriteArrayList<ClassAnimationString> animation_text,
			ClassAnimationTextureLoader animation_loader){
		this.path = path;
		this.screen_size = new Point(screen_size);
		this.animations = animations;
		this.animation_text = animation_text;
		this.animation_loader = animation_loader;
		spell_selector = new ClassHudFit();
		spell_selector.image = path + "icon_spell_selector.png";
		spell_selector.bottom_left = new Point(-1,-1);
		spell_selector.dimensions = new Point(-1,-1);
		enter_location = new Rectangle();
		spell_info = new SpellInfo();
		logger = new ClassLogDisplay("Class Hud Object");
		image_gold = "icon_gold.png";
		image_piety = "icon_piety.png";
		image_spells = "icon_spells.png";
		details = false;
		info = false;
		image_hud = "player_hud_normal.png";
		image_hud_details = "player_details_hud.png";
		logger.print("Init hud object");
		//hud_objects = new ArrayList<ClassHudFit>();
		//hud_text = new ArrayList<ClassHudText>();
		//rectangles = new ArrayList<ClassRectangle>();
	}
	public void refresh_hud(ClassCharacterPlayer player, ClassCursorAt cursor_object, ClassPlaceObjects objects){
		hud_objects = new ArrayList<ClassHudFit>();
		hud_text = new ArrayList<ClassHudText>();
		rectangles = new ArrayList<ClassRectangle>();
		spells = new ArrayList<ClassHudFit>();
		this.player = player;
		this.cursor_object = cursor_object;
		this.objects = objects;
		hud = new ClassHudFit();
		logger.print("Details start");
		logger.print(details);
		if(!details){
			hud.image = path + image_hud;
		}else{
			hud.image = path + image_hud_details;
		}
		logger.print(hud.image);
		hud.bottom_left = new Point(0,0);
		hud.dimensions = new Point(screen_size.x,3*screen_size.y/10);
		hud_wrapper = new ClassHudWrapper(screen_size,hud.dimensions,details,info,player);
		//hud_wrapper = new ClassHudWrapper(hud.dimensions,details,player);
		hud_objects.add(hud);
		
		//This is the location the player objects in the hud
		final Point info_spell_picture = new Point(2*hud.dimensions.x/3+hud.dimensions.x/14 - hud.dimensions.x/32,hud.dimensions.y/12);
		
		final Point size_spell_picture = new Point(screen_size.x/15,screen_size.y/15);
		if(!details){
			add_spell_objects(info_spell_picture,size_spell_picture);
		}
		
		//This is the location the player objects in the hud
		final Point info_player_picture = new Point(hud.dimensions.x/20+hud.dimensions.x/120,hud.dimensions.y/3 + hud.dimensions.y/6 + hud.dimensions.y/35);
		final Point size_player_picture = new Point(screen_size.x/12,screen_size.y/12);
		final Point rectangle_left = new Point(29*hud.dimensions.x/78,hud.dimensions.y/3-5*hud.dimensions.y/20);
		final Point rectangle_dimensions = new Point(hud.dimensions.x/3-hud.dimensions.x/42,hud.dimensions.y/15);
		add_player_objects(info_player_picture,size_player_picture,rectangle_left,rectangle_dimensions);
		
		//This is the location of objects on the hud (to the right of the player)
		final Point info_object_picture = new Point(38* hud.dimensions.x/100,50*hud.dimensions.y/100);
		final Point size_object_picture = new Point(19*screen_size.x/200,12*screen_size.y/100);
		
		//This is for icons at the bottom of the screen like the enemy attack indicator
		final Point info_gold_picture = new Point(hud.dimensions.x/2,18*hud.dimensions.y/35);
		
		final Point size_attacklives_picture = new Point(screen_size.x/40,screen_size.y/40);
		//if (cursor_object.get_object_type() == 5){
			
		//}
		//Cursor on Enemy
		final Point info_name_object = new Point(40*hud.dimensions.x/80,30*hud.dimensions.y/35);
		final Point info_description_object = new Point(40*hud.dimensions.x/80,26*hud.dimensions.y/35);
		final Point info_cost_object = new Point(40*hud.dimensions.x/80,22*hud.dimensions.y/35);
		
		logger.print("Object Type");
		logger.print(cursor_object.get_object_type());
		
		//Enemy
		if (cursor_object.get_object_type() == 1 && !info){
			final Point info_lives_picture = new Point(hud.dimensions.x/3 + hud.dimensions.x/6 + hud.dimensions.x/7,hud.dimensions.y/3 + 2*hud.dimensions.y/5 + hud.dimensions.y/20);
			final Point info_object_icon_picture = new Point(hud.dimensions.x/3 + hud.dimensions.x/6 + hud.dimensions.x/12,hud.dimensions.y/3 + 2*hud.dimensions.y/5 + hud.dimensions.y/20);
			final Point enemy_rectangle_left = new Point(35*hud.dimensions.x/80 - hud.dimensions.x/230,hud.dimensions.y/3-6*hud.dimensions.y/20);
			final Point enemy_rectangle_dimensions = new Point(hud.dimensions.x/4-hud.dimensions.x/15,hud.dimensions.y/15);
			
			add_enemy_objects(info_object_picture,size_object_picture,info_object_icon_picture,
					info_lives_picture,size_attacklives_picture,enemy_rectangle_left, enemy_rectangle_dimensions,
					info_name_object);
		}
		//Shop
		if (cursor_object.get_object_type() == 2 && !info){
			add_shop_objects(info_object_picture, size_object_picture, info_gold_picture, 
					size_attacklives_picture,info_name_object,info_description_object);
		}
		//Pickup
		if (cursor_object.get_object_type() == 3 && !info){
			add_pickup_objects(info_object_picture, size_object_picture, info_name_object,info_description_object);
		}
		//Totem
		if (cursor_object.get_object_type() == 4 && !info){
			//add_pickup_objects(info_object_picture, size_object_picture, info_name_object,info_description_object);
		}
		//Spell
		if (cursor_object.get_object_type() == 5 && !info){
			add_spell_objects(info_object_picture, size_object_picture, info_name_object,info_description_object,
					info_gold_picture,size_attacklives_picture);
		}
		if (cursor_object.get_object_type() == 6 && !info){
			logger.print("In gods");
			add_god_objects(info_object_picture, size_object_picture, info_gold_picture, 
					size_attacklives_picture,info_name_object,info_description_object);
		}
		print_player_text();
		
		//This is where the bounds for the click rectangles are defined
		//private Rectangle mana_potion,health_potion,player_info,enemy_info;
		//health potion click
		final Point mana_potion_click_location = new Point(6*hud.dimensions.x/200,8*hud.dimensions.y/100);
		final Point mana_potion_click_dimensions = new Point(10*hud.dimensions.x/100,32*hud.dimensions.y/100);
		//Uncomment these lines to show the bounding box for the health potion click
		//ClassRectangle rect_holder = new ClassRectangle(mana_potion_click_location,mana_potion_click_dimensions,new Vector3(1,0,0));
		//rectangles.add(rect_holder);
		
		health_potion = new Rectangle(mana_potion_click_location.x,mana_potion_click_location.y,mana_potion_click_dimensions.x,mana_potion_click_dimensions.y);
		
		//mana potion click
		//Uncomment these lines to show the bounding box for the mana potion click
		final Point health_potion_click_location = new Point(28*hud.dimensions.x/200,8*hud.dimensions.y/100);
		final Point health_potion_click_dimensions = new Point(10*hud.dimensions.x/100,32*hud.dimensions.y/100);
		//Uncomment these lines to show the bounding box for the mana potion click
		//ClassRectangle rect_holder2 = new ClassRectangle(health_potion_click_location,health_potion_click_dimensions,new Vector3(0,0,1));
		//rectangles.add(rect_holder2);
		
		mana_potion = new Rectangle(health_potion_click_location.x,health_potion_click_location.y,health_potion_click_dimensions.x,health_potion_click_dimensions.y);
		hud_wrapper.merge_objects(hud_objects, hud_text, rectangles);
	}
	public void add_spell_objects(Point info_object_picture, Point size_object_picture, Point info_name_object, 
			Point info_description_object, Point spell_picture, Point spell_pic_size){
		ClassHudFit spell_icon = new ClassHudFit();
		spell_icon.image = path + cursor_object.spell.get_spell_info().Image;
		spell_icon.bottom_left = new Point(info_object_picture);
		spell_icon.dimensions = new Point(size_object_picture);
		hud_objects.add(spell_icon);
		hud_text.add(new ClassHudText(info_name_object,cursor_object.spell.get_spell_info().Name,12));
		hud_text.add(new ClassHudText(info_description_object,cursor_object.spell.get_spell_info().Description,11));
		//hud_text.add(new ClassHudText(info_cost_object,"Mana: " + String.valueOf(cursor_object.spell.get_spell_info().cost),9));
		//info_cost_object
		//ClassHudFit magic_icon = new ClassHudFit();
		//magic_icon.image = path + image_spells;
		//magic_icon.bottom_left = new Point(spell_picture);
		//magic_icon.dimensions = new Point(spell_pic_size);
		//hud_objects.add(magic_icon);
		final Point info_spell_cost = new Point(info_description_object.x,spell_picture.y + hud.dimensions.y/10);
		hud_text.add(new ClassHudText(info_spell_cost,"Mana Cost: " + String.valueOf(cursor_object.spell.get_spell_info().cost),11));
	}
	public void add_pickup_objects(Point info_object_picture, Point size_object_picture, Point info_name_object, Point info_description_object){
		ClassHudFit pickup_icon = new ClassHudFit();
		pickup_icon.image = path + cursor_object.pickup.get_pickup_info().Image;
		pickup_icon.bottom_left = new Point(info_object_picture);
		pickup_icon.dimensions = new Point(size_object_picture);
		hud_objects.add(pickup_icon);
		hud_text.add(new ClassHudText(info_name_object,cursor_object.pickup.get_pickup_info().Name,11));
		hud_text.add(new ClassHudText(info_description_object,cursor_object.pickup.get_pickup_info().Description,11));
	}
	public void print_player_text(){
		ArrayList<ClassHudText> player_text = new ArrayList<ClassHudText>();
		
		final Point info_mana_potion = new Point(21*hud.dimensions.x/100,25*hud.dimensions.y/100);
		final Point info_health_potion = new Point(10*hud.dimensions.x/100,25*hud.dimensions.y/100);
		
		final Point info_attack = new Point(29*hud.dimensions.x/100, 43*hud.dimensions.y/100);
		final Point info_gold = new Point(29*hud.dimensions.x/100, 28*hud.dimensions.y/100);
		final Point info_piety = new Point(29*hud.dimensions.x/100, 15*hud.dimensions.y/100);
		
		final Point info_player_class = new Point(hud.dimensions.x/6,hud.dimensions.y/3 + 2*hud.dimensions.y/4);
		
		player_text.add(new ClassHudText(info_attack,String.valueOf(this.player.get_total_attack()),12));
		player_text.add(new ClassHudText(info_gold,String.valueOf(this.player.gold),12));
		player_text.add(new ClassHudText(info_piety,String.valueOf(this.player.get_player_variable("piety")),12));
		
		player_text.add(new ClassHudText(info_health_potion,String.valueOf(this.player.health_potions),26));
		player_text.add(new ClassHudText(info_mana_potion,String.valueOf(this.player.mana_potions),26));
		
		player_text.add(new ClassHudText(info_player_class,player.player_race_info.get_race_info().Name + " " + player.player_class_info.Name,12));
		
		hud_wrapper.set_player_text(player_text);
	}
	public void add_shop_objects(Point info_object_picture, Point size_object_picture, Point info_gold_picture, 
			Point size_attacklives_picture, Point info_name_object, Point info_description_object){
		ClassHudFit shop_icon = new ClassHudFit();
		shop_icon.image = path + cursor_object.shop.get_shop_image();
		shop_icon.bottom_left = new Point(info_object_picture);
		shop_icon.dimensions = new Point(size_object_picture);
		
		hud_wrapper.set_enterable_icon(shop_icon, 
				new ClassHudText(info_name_object,cursor_object.shop.get_shop_name(),12),
				new ClassHudText(info_description_object,cursor_object.shop.get_shop_details(),9));
		
		
		//hud_objects.add(shop_icon);
		//hud_text.add(new ClassHudText(info_name_object,cursor_object.shop.get_shop_name(),9));
		//hud_text.add(new ClassHudText(info_description_object,cursor_object.shop.get_shop_details(),9));
		
		enter_location = hud_wrapper.add_enter_button(cursor_object.shop.all_used(),false,objects.worshipping_god(),objects.worshipping_god());
		//Point info_disclaimer_shop = new Point(info_description_object.x,info_description_object.y-(4*hud.dimensions.y/35));
		//hud_text.add(new ClassHudText(info_disclaimer_shop,cursor_object.shop.get_shop_disclaimer(),9));
		
		if(!info){
			hud_wrapper.set_detail_assets(1, path + image_gold, String.valueOf(cursor_object.shop.get_price(0)), 
					String.valueOf(cursor_object.shop.get_shop_info(0).Name)+": ", 
					String.valueOf(cursor_object.shop.get_shop_info(0).Description),
					!cursor_object.shop.get_shop_info(0).purchased, false);
			hud_wrapper.set_detail_assets(2, path + image_gold, String.valueOf(cursor_object.shop.get_price(1)), 
					String.valueOf(cursor_object.shop.get_shop_info(1).Name)+": ", 
					String.valueOf(cursor_object.shop.get_shop_info(1).Description),
					!cursor_object.shop.get_shop_info(1).purchased, false);
			hud_wrapper.set_detail_assets(3, path + image_gold, String.valueOf(cursor_object.shop.get_price(2)), 
					String.valueOf(cursor_object.shop.get_shop_info(2).Name)+": ", 
					String.valueOf(cursor_object.shop.get_shop_info(2).Description),
					!cursor_object.shop.get_shop_info(2).purchased, false);
			hud_wrapper.set_detail_banner(image_gold,image_piety,cursor_object.shop.get_shop_name(), cursor_object.shop.get_shop_details(), false, false);
		}
		
			
	}
	public void add_god_objects(Point info_object_picture, Point size_object_picture, Point info_gold_picture, 
			Point size_attacklives_picture, Point info_name_object, Point info_description_object){
		ClassHudFit god_icon = new ClassHudFit();
		god_icon.image = path + cursor_object.god.get_god_info().Image;
		god_icon.bottom_left = new Point(info_object_picture);
		god_icon.dimensions = new Point(size_object_picture);
		hud_wrapper.set_enterable_icon(god_icon, 
				new ClassHudText(info_name_object,cursor_object.god.get_god_info().Name,12),
				new ClassHudText(info_description_object,cursor_object.god.get_god_info().Description,9));
		//hud_objects.add(god_icon);
		//ClassHudFit piety_icon = new ClassHudFit();
		//piety_icon.image = path + image_piety;
		//piety_icon.bottom_left = new Point(info_gold_picture);
		//piety_icon.dimensions = new Point(size_attacklives_picture);
		//hud_objects.add(piety_icon);
		//hud_text.add(new ClassHudText(info_name_object,cursor_object.god.get_god_info().Name,9));
		//hud_text.add(new ClassHudText(info_description_object,cursor_object.god.get_god_info().Description,9));
		//final Point info_shop_cost = new Point(info_gold_picture.x + hud.dimensions.x/33,info_gold_picture.y + hud.dimensions.y/10);
		//hud_text.add(new ClassHudText(info_shop_cost,String.valueOf(cursor_object.shop.get_price()),9));
		if(!info){
			if(cursor_object.god.get_god_info().ritual_levels[0] != -1){
				hud_wrapper.set_detail_assets(1, path + image_piety, String.valueOf(cursor_object.god.get_god_info().ritual_levels[0]), 
						"", String.valueOf(cursor_object.god.get_god_info().ritual_description[2]), cursor_object.god.worshipping, true);
			}
			if(cursor_object.god.get_god_info().ritual_levels[1] != -1){
				hud_wrapper.set_detail_assets(2, path + image_piety, String.valueOf(cursor_object.god.get_god_info().ritual_levels[1]), 
						"", String.valueOf(cursor_object.god.get_god_info().ritual_description[3]),cursor_object.god.worshipping, true);
			}
			if(cursor_object.god.get_god_info().ritual_levels[2] != -1){
				hud_wrapper.set_detail_assets(3, path + image_piety, String.valueOf(cursor_object.god.get_god_info().ritual_levels[2]), 
						"", String.valueOf(cursor_object.god.get_god_info().ritual_description[4]),cursor_object.god.worshipping, true);
			}
			hud_wrapper.set_detail_banner(image_gold,image_piety,cursor_object.god.get_god_info().Name, cursor_object.god.get_god_info().Description, cursor_object.god.worshipping, true);
		}
		
		enter_location = hud_wrapper.add_enter_button(false,true,objects.worshipping_god(),cursor_object.god);
		
	}
	public void add_enemy_objects(Point info_enemy_picture, Point size_enemy_picture, 
			Point info_attack_picture, Point info_lives_picture, Point size_attacklives_picture,
			Point rectangle_left, Point rectangle_dimensions, Point info_name_enemy){
		int space = hud.dimensions.y/8;
		
		final Point info_attack_enemy = new Point(info_lives_picture.x + 2*hud.dimensions.x/100,info_attack_picture.y+7*hud.dimensions.y/100);
		final Point info_lives_enemy = new Point(info_lives_picture.x + 2*hud.dimensions.x/100,info_lives_picture.y-4*hud.dimensions.y/100);
		final Point info_predict_enemy = new Point(info_lives_picture.x - 1*hud.dimensions.x/100,info_lives_picture.y-12*hud.dimensions.y/100);
		hud_text.add(new ClassHudText(info_name_enemy,cursor_object.enemy.get_name(),14));
		hud_text.add(new ClassHudText(info_attack_enemy,String.valueOf(cursor_object.enemy.attack),12));
		hud_text.add(new ClassHudText(info_lives_enemy,String.valueOf(cursor_object.enemy.lives),12));
		
		Color return_color = new Color();
		return_color.set(Color.WHITE);
		
		String outcome = String.valueOf(player.get_player_predict_outcome(cursor_object.enemy));
		
		if(outcome.equals("Victory")){
			return_color.set(Color.GREEN);
		}else if(outcome.equals("Safe")){
			return_color.set(Color.ORANGE);
		}else if(outcome.equals("Warning")){
			return_color.set(Color.YELLOW);
		}else{
			return_color.set(Color.RED);
		}
		
		hud_text.add(new ClassHudText(info_predict_enemy,outcome,12,return_color));
		
		logger.print("Enemy Found");
		ClassHudFit enemy_icon = new ClassHudFit();
		enemy_icon.image = path + cursor_object.enemy.enemy_info.Image;
		enemy_icon.bottom_left = new Point(info_enemy_picture);
		enemy_icon.dimensions = new Point(size_enemy_picture);
		hud_objects.add(enemy_icon);
		if(!player.get_attack_mod("Static") && !player.get_contracted_mod("Static")){
			ClassHudFit level_icon = new ClassHudFit();
			level_icon.image = path + cursor_object.enemy.level_image + ".png";
			level_icon.bottom_left = new Point(info_enemy_picture);
			level_icon.dimensions = new Point(size_enemy_picture.x/2,size_enemy_picture.y/2);
			hud_objects.add(level_icon);
		}
		
		final Point info_mods_enemy = new Point(info_name_enemy.x,info_name_enemy.y-hud.dimensions.y/5);
		//This adds the enemy modifiers
		for(int i = 0; i < cursor_object.enemy.get_attack_mods().size();i++){
			if(cursor_object.enemy.get_attack_mods().get(i).get_has_mod()){
				ClassHudFit mod_icon = new ClassHudFit();
				mod_icon.image = path + cursor_object.enemy.get_attack_mods().get(i).get_info_mods().Image;
				mod_icon.bottom_left = new Point(info_mods_enemy);
				mod_icon.dimensions = new Point(size_attacklives_picture);
				hud_objects.add(mod_icon);
				info_mods_enemy.move(info_mods_enemy.x + hud.dimensions.x/40, info_mods_enemy.y);
			}
		}
		
		//Enemy Attack
		ClassHudFit attack_icon = new ClassHudFit();
		attack_icon.image = path + "icon_attackboost.png";
		attack_icon.bottom_left = new Point(info_lives_picture.x-1*hud.dimensions.x/100,info_attack_picture.y-0*hud.dimensions.y/100);
		attack_icon.dimensions = new Point(size_attacklives_picture);
		hud_objects.add(attack_icon);
		//Enemy Lives
		ClassHudFit lives_icon = new ClassHudFit();
		lives_icon.image = path + "icon_life.png";
		lives_icon.bottom_left = new Point(info_lives_picture.x-1*hud.dimensions.x/100,info_attack_picture.y-10*hud.dimensions.y/100);
		lives_icon.dimensions = new Point(size_attacklives_picture);
		hud_objects.add(lives_icon);
		
		//Healthbars
		logger.print("Enemy HealthBar Created");
		//enemy health
		ClassRectangle e_health_predicted = new ClassRectangle(new Point(rectangle_left.x + rectangle_left.x/7,
				rectangle_left.y + space*4-space/4),new Point((int)((rectangle_dimensions.x * (cursor_object.enemy.health_left()))),rectangle_dimensions.y),
				new Vector3(.37f,.19f,.50f));
		logger.print("Enemy Health Bar Left");
		logger.print(e_health_predicted.edge);
		logger.print("Enemy Health Bar Dims");
		logger.print(e_health_predicted.dimension);
		logger.print("Enemy Remaining Health");
		ClassLogDisplay.print(cursor_object.enemy.predict_remaining_health(player));
		
		//get_spell_damage("ManaSpark", cursorOn, player, objects);
		
		//if(cursor_object.enemy.predict_remaining_health(player)>=0){
			logger.print("Health Greater than zero");
			ClassRectangle e_health_actual = new ClassRectangle(new Point(rectangle_left.x + rectangle_left.x/7,
					rectangle_left.y + space*4-space/4),
					new Point((int)((rectangle_dimensions.x * (((float)cursor_object.enemy.predict_remaining_health(player))/(float)cursor_object.enemy.max_health))),
					rectangle_dimensions.y),new Vector3(1,0,0));
			logger.print("Enemy Health Bar Predicted Left");
			logger.print(e_health_actual.edge);
			logger.print("Enemy Health Bar Predicted Dims");
			logger.print(e_health_actual.dimension);
			if(spell_info.get_selected_index() != -1 && player.get_spells()[spell_info.get_selected_index()].get_spell_info().attack_spell){
				
				ClassRectangle mana_predicted = new ClassRectangle(new Point(e_health_predicted.edge.x,e_health_predicted.edge.y),
						new Point(e_health_predicted.dimension.x,e_health_predicted.dimension.y/2),new Vector3(.804f,.4f,.113f));
				
				ClassRectangle mana_actual = new ClassRectangle(new Point(e_health_predicted.edge.x,e_health_predicted.edge.y),
						new Point(e_health_predicted.dimension.x,e_health_predicted.dimension.y/2),new Vector3(1,0,0));
				
				float spell_cost = player.get_spells()[spell_info.get_selected_index()].get_spell_cost(player);
				float current_mana = (float) player.get_player_variable("current_mana");
				ClassObjectSpellDungeon spell = player.get_spells()[spell_info.get_selected_index()];
				float spell_damage = (float) spell.predict_spell_damage(spell.get_spell_info().Name, 
						cursor_object, player, objects);
				
				if(spell_cost<=current_mana && current_mana-spell_cost>=0){
					e_health_actual.dimension.y /= 2;
					e_health_actual.edge.y += e_health_actual.dimension.y;
					
					e_health_predicted.dimension.y /= 2;
					e_health_predicted.edge.y += e_health_predicted.dimension.y;
					
					mana_actual.dimension.x = (int)(rectangle_dimensions.x * (((float)cursor_object.enemy.current_health - spell_damage)/(float)cursor_object.enemy.max_health));
					
					ClassLogDisplay.print("Printing Rectangle");
					rectangles.add(mana_predicted);
					if(mana_actual.dimension.x > 0){
						rectangles.add(mana_actual);
					}
				}
				
				/*cursor_object, spell_info.get_selected_index()
				if(spell_index != -1){
					ClassLogDisplay.print("Spell Selected!");
					
					float spell_cost = player.get_spells()[spell_index].get_spell_cost(player);
					float current_mana = (float) player.get_player_variable("current_mana");
					float total_mana = (float) player.get_player_variable("max_mana");
					
					if(spell_cost<=current_mana){
						mana.dimension.x = (int)((float) bar_dimensions.x * ((current_mana-spell_cost)/total_mana));
						if(current_mana-spell_cost>0){
							ClassLogDisplay.print("Printing Rectangle");
							rectangles.add(mana);
						}
					}else{
						rectangles.add(mana);
					}
				}else{
					ClassLogDisplay.print("No Spell Selected!");
					rectangles.add(mana);
				}*/
			}
			rectangles.add(e_health_predicted);
			if(e_health_actual.dimension.x > 0){
				rectangles.add(e_health_actual);
			}
		/*}else{
			rectangles.add(e_health_predicted);
		}*/
		final Point info_text_enemy_health = new Point(e_health_predicted.edge.x + hud.dimensions.x/12,e_health_predicted.dimension.y + e_health_predicted.edge.y);
		hud_text.add(new ClassHudText(info_text_enemy_health,cursor_object.enemy.get_health_ratio(),12));
		
		//ClassRectangle damage_predictor = = new ClassRectangle(health.edge,new Point(health.dimension.x,health.dimension.y),new Vector3(204,153,255));
		//health
		logger.print("Health Predict width");
		ClassLogDisplay.print(rectangle_dimensions.x * (this.player.current_health-cursor_object.enemy.attack));
		logger.print("Health Exact width");
	}
	public void add_spell_objects(Point info_spell_picture, Point size_spell_picture){
		Point[] spell_locs = new Point[]{
				new Point(info_spell_picture),
				new Point(info_spell_picture.x+hud.dimensions.x/14,info_spell_picture.y),
				new Point(info_spell_picture.x+2*hud.dimensions.x/14,info_spell_picture.y),
				new Point(info_spell_picture.x+3*hud.dimensions.x/14,info_spell_picture.y)	
		};
		spell_areas = new Rectangle[]{
				new Rectangle(spell_locs[0].x,spell_locs[0].y,size_spell_picture.x,size_spell_picture.y),
				new Rectangle(spell_locs[1].x,spell_locs[1].y,size_spell_picture.x,size_spell_picture.y),
				new Rectangle(spell_locs[2].x,spell_locs[2].y,size_spell_picture.x,size_spell_picture.y),
				new Rectangle(spell_locs[3].x,spell_locs[3].y,size_spell_picture.x,size_spell_picture.y)	
		};
		
		for(int i = 0;i<player.get_spells().length;i++){
			if(player.get_spells()[i].get_spell_info() != null){
				ClassHudFit spell_icon = new ClassHudFit();
				spell_icon.image = path + player.get_spells()[i].get_spell_info().Image;
				spell_icon.bottom_left = new Point(spell_locs[i]);
				spell_icon.dimensions = new Point(size_spell_picture);
				hud_objects.add(spell_icon);
			}
		}
		if(spell_selector.bottom_left.x!=-1 && spell_selector.bottom_left.y!=-1 &&
				spell_selector.dimensions.x!=-1 && spell_selector.dimensions.y!=-1){
			hud_objects.add(spell_selector);
		}
		if(spell_info.get_visible()){
			hud_text.add(spell_info.get_title());
			hud_text.add(spell_info.get_description());
			hud_text.add(spell_info.get_cost());
			rectangles.add(hud_wrapper.add_spell_trash_button());
			//hud_text.add(spell_info.get_trash_button_text());
		}
		final Point spell_label = new Point(info_spell_picture.x,info_spell_picture.y + 28*hud.dimensions.y/100);
		//TODO: Uncomment to put the spell header back in. Dont forget to change size_spell_picture back to Point(screen_size.x/12,screen_size.y/12);
		//hud_text.add(new ClassHudText(spell_label,"Spells",12));
	}
	public void add_player_objects(Point info_player_picture, Point size_player_picture, Point rectangle_left, Point rectangle_dimensions){
		ClassRectangle rect_holder = hud_wrapper.set_main_picture();
		player_info = new Rectangle(rect_holder.edge.x, rect_holder.edge.y, rect_holder.dimension.x, rect_holder.dimension.y);
		
		//To set the info for the details screen
		if(info){
			hud_wrapper.set_detail_banner(image_gold,image_piety,"Level: " + player.get_player_variable("level"), 
					player.player_race_info.get_race_info().Name + " " + player.player_class_info.Name, false, false);
			/*
			 * public void set_player_variable_float(String variable, float value){
		if (variable.equals("double_hit")){double_hit = value;}
		if (variable.equals("dodge")){dodge = value;}
		if (variable.equals("death_gaze")){death_gaze = value;}
		if (variable.equals("life_steal")){life_steal = value;}
		if (variable.equals("phys_atk")){phys_atk = value;}
		if (variable.equals("mag_atk")){mag_atk = value;}
		if (variable.equals("phys_def")){phys_def = value;}
		if (variable.equals("mag_def")){mag_def = value;}
		if (variable.equals("health_potion_effectiveness")){health_potion_effectiveness = value;health_potion_effectiveness=health_potion_effectiveness>1?1:health_potion_effectiveness;}
		if (variable.equals("mana_potion_effectiveness")){mana_potion_effectiveness = value;mana_potion_effectiveness=mana_potion_effectiveness>1?1:mana_potion_effectiveness;}
	}
			 */
			String race_label = "Race:";
			String[] race_array = split_string(player.player_race_info.get_race_info().Description,45);
			String class_label = "Class:";
			String[] class_array = split_string(player.player_class_info.Description,45);
			
			ArrayList<String> mid_details = new ArrayList<String>();
			mid_details.add(race_label);
			mid_details.addAll(Arrays.asList(race_array));
			mid_details.add(class_label);
			mid_details.addAll(Arrays.asList(class_array));
			
			String[] return_array = new String[mid_details.size()];
			return_array = mid_details.toArray(return_array);
			
			ArrayList<String> buffs = new ArrayList<String>();
			
			buffs.add("Buffs:");
			
			String immune_string = "";
			for(ClassCharacterModDungeon mod:player.get_class_mods().immune_mods){
				immune_string = "Imm: "+mod.return_mod_name();
				if(!buffs.contains(immune_string) && mod.get_has_mod()){
					buffs.add(immune_string);
				}
			}
			for(ClassCharacterModDungeon mod:player.get_class_mods().attack_mods){
				if(!buffs.contains(mod.return_mod_name()) && mod.get_has_mod()){
					buffs.add(mod.return_mod_name());
				}
			}
			for(ClassCharacterModDungeon mod:player.get_class_mods().contracted_mods){
				if(!buffs.contains(mod.return_mod_name()) && mod.get_has_mod()){
					buffs.add(mod.return_mod_name());
				}
			}
			
			String[] buff_array = new String[buffs.size()];
			buff_array = buffs.toArray(buff_array);
			
			hud_wrapper.set_info_asset(
					new String[]{/*"Atk: " + player.attack,*/
							"Physical Atk: " + (int)((1f+player.get_player_variable_float("phys_atk")+player.get_attack_bonus())*100) + "%",
							"Magic Atk: " + (int)((1f+player.get_player_variable_float("mag_atk"))*100) + "%",
							"Physical Def: " + (int)((1f+player.get_player_variable_float("phys_def"))*100) + "%",
							"Magic Def: " + (int)((1f+player.get_player_variable_float("mag_def"))*100) + "%",
							"Living Bonus: " + (int)((player.get_class_mods().playerAttackMod.living_bonus())*100f) + "%",
							"Undead Bonus: " + (int)((player.get_class_mods().playerAttackMod.undead_bonus())*100f) + "%",
							"Double Hit: " + (int)((player.get_player_variable_float("double_hit"))*100f) + "%",
							"Evade Chance: " + (int)((player.get_player_variable_float("dodge"))*100f) + "%",
							"Death Gaze: " + (int)((player.get_player_variable_float("death_gaze"))*100f) + "%",
							"Life Steal: " + (int)((player.get_player_variable_float("life_steal"))*100f) + "%",
							"Spell Damage: " + (int)((1f+player.get_class_mods().playerSpellMod.spell_strength)*100f) + "%"},
					return_array,
					buff_array);
		}
		
		ArrayList<ClassHudFit> wrapper_hud_objects = new ArrayList<ClassHudFit>();
		
		final Point info_mods_enemy = new Point(info_player_picture.x - hud.dimensions.x/53,info_player_picture.y - hud.dimensions.y/30);
		//This adds the enemy modifiers
		for(int i = 0; i < player.get_attack_mods().size();i++){
			//If the player contracted a mod and it's an ailment...
			if(player.get_contracted_mods().get(i).get_has_mod()){
				logger.print(player.get_contracted_mods().get(i).get_info_mods().Name);
				ClassHudFit mod_icon = new ClassHudFit();
				mod_icon.image = path + player.get_attack_mods().get(i).get_info_mods().Image;
				mod_icon.bottom_left = new Point(info_mods_enemy);
				mod_icon.dimensions = new Point(size_player_picture.x/4,size_player_picture.y/4);
				wrapper_hud_objects.add(mod_icon);
				//hud_objects.add(mod_icon);
				info_mods_enemy.move(info_mods_enemy.x, info_mods_enemy.y + hud.dimensions.y/10);
			}
		}
		
		hud_wrapper.set_player_mods(wrapper_hud_objects);
		hud_wrapper.set_player_action_bars(cursor_object, spell_info.get_selected_index());
	}
	public String[] split_string(String splitter_string, int length){
		ArrayList<String> return_list = new ArrayList<String>();
		
		for(int i = 0; i < splitter_string.length(); i+=length){
			if(i+length > splitter_string.length()){
				return_list.add(splitter_string.substring(i,splitter_string.length()));
			}else{
				return_list.add(splitter_string.substring(i,i+length));
			}
		}
		
		String[] return_array = new String[return_list.size()];
		return_array = return_list.toArray(return_array);
		
		return return_array;
	}
	public void reset_details(){
		info = false;
		details = false;
	}
	public boolean check_hud_click(Point click_location, String path){
		logger.print("hud_clicked");
		logger.print(click_location);
		logger.print("health_potion location");
		logger.print(String.valueOf(health_potion.x) + " : " + String.valueOf(health_potion.y) + " " + String.valueOf(health_potion.width) + " : " + String.valueOf(health_potion.height));
		logger.print("details");
		logger.print(details);
		logger.print("click_return");
		logger.print(""+hud_wrapper.check_location(click_location));
		int details_click_location = hud_wrapper.check_location(click_location);
		if(health_potion.contains(click_location.x, click_location.y)){
			logger.print("Health Potion!");
			player.use_potion(true);
			return true;
		}else if(mana_potion.contains(click_location.x, click_location.y)){
			logger.print("Mana Potion!");
			player.use_potion(false);
			return false;
		}else if((cursor_object.get_object_type() == 2 || cursor_object.get_object_type() == 6) 
				&& enter_location.contains(click_location.x, click_location.y) && !details){
			details = true;
			logger.print("details");
			player.location = cursor_object.location;
			return true;
		}else if(cursor_object.get_object_type() == 6 && objects.worshipping_god() == null 
			&& enter_location.contains(click_location.x, click_location.y) && details){
			//This means that the player wants to worship this god...
			player.set_god(cursor_object.god);
			cursor_object.god.accept_god(player, objects);
			cursor_object.god.worshipping = true;
		}else if(spell_info.get_visible() && spell_info.get_trash_button_rectangle().contains(click_location.x, click_location.y)){
			player.trash_spell(spell_info.index);
			spell_info.set_visible(false);
		}else if(details && details_click_location != -1){
			//Shop
			if(cursor_object.get_object_type() == 2){
				cursor_object.shop.use_shop(player, details_click_location);
			}
			//Altar
			if(cursor_object.get_object_type() == 6){
				cursor_object.god.perform_ritual(player, details_click_location);
			}
		}else if(player_info.contains(click_location.x, click_location.y)){
			info = true;
			details = true;
		}
		for(int i = 0; i < spell_areas.length;i++){
			if(spell_areas[i].contains(click_location.x, click_location.y) && player.get_spells()[i].get_spell_info()!=null){
				if (spell_selector.contains(click_location)){
					player.get_spells()[i].use_spell(player, cursor_object, objects, animations, animation_text, animation_loader);
					spell_selector.bottom_left.move(-1,-1);
					spell_selector.dimensions.move(-1,-1);
					spell_info.set_visible(false);
				}else{
					spell_selector.bottom_left.move((int)spell_areas[i].x,(int)spell_areas[i].y);
					spell_selector.dimensions.move((int)spell_areas[i].width,(int)spell_areas[i].height);
					spell_info.set_spell_info(i,new Point((int)spell_areas[0].x,(int)spell_areas[0].y));
					spell_info.set_visible(true);
				}
				return true;
			}
		}
		return false;
	}
	public void reset_spell_selector(){
		spell_selector.bottom_left.move(-1,-1);
		spell_selector.dimensions.move(-1,-1);
	}
	public ArrayList<ClassHudFit> get_spells(){
		return spells;
	}
	public ArrayList<ClassHudFit> get_hud_objects(){
		return hud_objects;
	}
	public ArrayList<ClassHudText> get_hud_text(){
		return hud_text;
	}
	public Point get_hud_dimensions(){
		return hud.dimensions;
	}
	public ArrayList<ClassRectangle> get_rectangles(){
		return rectangles;
	}
	class SpellInfo{
		private int index;
		private Point left_coord;
		private boolean visible;
		private ClassRectangle trash_button;
		SpellInfo(){
			index = -1;
			left_coord = new Point();
			visible = false;
			trash_button = new ClassRectangle(new Point(0,0),new Point(0,0),button_color);
		}
		public void set_visible(boolean visible){
			this.visible = visible;
		}
		public boolean get_visible(){
			return visible;
		}
		public int get_selected_index(){
			return spell_selector.dimensions.x == -1 && spell_selector.dimensions.y == -1?-1:index;
		}
		public void set_spell_info(int index, Point left_coord){
			this.index = index;
			this.left_coord.move(left_coord);
		}
		/*public ClassRectangle get_trash_button(){
			trash_button.edge = new Point(left_coord.x + hud.dimensions.x/7, left_coord.y + hud.dimensions.y/3 + hud.dimensions.y/20);
			trash_button.dimension = new Point(hud.dimensions.x/12,4* hud.dimensions.y/24);
			return trash_button;
		}*/
		public Rectangle get_trash_button_rectangle(){
			ClassRectangle trash_button = hud_wrapper.add_spell_trash_button();
			return new Rectangle(trash_button.edge.x,trash_button.edge.y,trash_button.dimension.x,trash_button.dimension.y);
		}
		public ClassHudText get_trash_button_text(){
			final Point button_text = new Point(trash_button.edge.x + hud.dimensions.x/80,trash_button.edge.y + hud.dimensions.y/9);
			return new ClassHudText(button_text,"Trash Spell",12);
		}
		public ClassHudText get_title(){
			ClassObjectSpellDungeon selected_spell= player.get_spells()[index];
			final Point spell_title = new Point(left_coord.x,left_coord.y + hud.dimensions.y/2 + hud.dimensions.y/3);
			return new ClassHudText(spell_title,selected_spell.get_spell_info().Name,14);
		}
		public ClassHudText get_description(){
			ClassObjectSpellDungeon selected_spell= player.get_spells()[index];
			final Point spell_description = new Point(left_coord.x + hud.dimensions.x/100,left_coord.y + 2*hud.dimensions.y/3 + hud.dimensions.y/20);
			return new ClassHudText(spell_description,selected_spell.get_spell_info().Description,13);
		}
		public ClassHudText get_cost(){
			ClassObjectSpellDungeon selected_spell= player.get_spells()[index];
			final Point spell_description = new Point(left_coord.x + hud.dimensions.x/80,left_coord.y + 58*hud.dimensions.y/100);
			return new ClassHudText(spell_description,"Mana Cost: " + selected_spell.get_spell_cost(player),13);
		}
	}
}
